import random
import string
import json


def gen_username(prefix =None):
    if prefix:
        if len(prefix)>8:
            raise Exception("prefix length larger than 8")
        elif prefix:
            return prefix + "".join(random.sample(string.ascii_letters+string.digits,8-len(prefix)))
    return "".join(random.sample(string.ascii_letters+string.digits,8))

def json_load(str1):
    if str1:
        return json.loads(str1.encode('utf8'))
    else:
        return dict()

def dict_list_add(dict1,key,value):
    if dict1.get(key, None):
        dict1[key].append(value)
    else:
        dict1[key] = [value]


